package com.myk.game.heroscuffle.game;

import java.util.ArrayList;
import java.util.List;

public class HateRecorder {

    public static final int HATE_TYPE_ATTACK = 0;
    public static final int HATE_TYPE_EFFECT = 1;
    public static final int HATE_TYPE_TREAT = 2;

    private final List<HateGroup> center = new ArrayList<>();

    /**
     * 记录仇恨
     *
     * @param round 发生的回合数
     * @param sender 主动发起者
     * @param receiver 被动接受者
     * @param type 0:主动攻击伤害  1:技能范围伤害   2:治疗保护恩情
     */
    public void record(int round,Hero sender,Hero receiver,int type){
        if (round > getRecentRound()){ //新的一回合增加新的记录集合
            center.add(new HateGroup(round));
        }
        HateGroup recentHateGroup = getRecentHateGroup();
        recentHateGroup.hateItemList.add(new HateItem(sender,receiver,type));
    }

    /**
     * 获得最近一次记录的回合
     */
    public int getRecentRound(){
        if (center.size() == 0) {
            return 0;
        }
        else {
            return center.get(center.size()-1).round;
        }
    }

    /**
     * 获得最近一回合的仇恨记录
     */
    public HateGroup getRecentHateGroup(){
        if (center.size() == 0){
            return null;
        }
        else {
            return center.get(center.size()-1);
        }
    }

    public static class HateGroup{
        public int round; //当前回合数
        public List<HateItem> hateItemList; //仇恨集合

        public HateGroup(int round) {
            this.round = round;
            hateItemList = new ArrayList<>();
        }
    }

    public static class HateItem{
        public Hero attacker; //攻击者
        public Hero attacked; //被攻击者
        public int type; //仇恨or恩情类型 0:主动攻击伤害  1:技能范围伤害   2:治疗保护恩情

        public HateItem(Hero attacker, Hero attacked, int type) {
            this.attacker = attacker;
            this.attacked = attacked;
            this.type = type;
        }
    }
}
